package design.patterns.proxymode.dynamicProxy.service;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Description :
 * @author: cww
 * @DateTime: 2018-07-21 16:06
 */

public class LogHandler implements InvocationHandler{
    private Object object;

    public LogHandler(Object object){
        super();
        this.object = object;
    }

    /**
     * 创建代理对象并返回该对象
     * @return
     */
    public Object getProxy() {

        return Proxy.newProxyInstance(object.getClass().getClassLoader(),object.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("=====dynamicProxy-参数为"+args[0]+"=====");
        method.invoke(object,args[0]);
        System.out.println("=====动态代理结束=====");
        return null;
    }
}
